package cfengMiddleware.server.springEventDriven.consumer;

import cfengMiddleware.server.springEventDriven.event.LoginEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;

/**
 * @author Cfeng
 * @date 2022/9/15
 * 事件驱动 -- 消费者
 */

@Component
@EnableAsync //异步多线程
@Slf4j
public class Consumer implements ApplicationListener<LoginEvent> {


    //监听消费消息
    @Override
    @Async //开启新的线程执行
    public void onApplicationEvent(LoginEvent event) {
        log.info("Spring事件驱动---- 消费者接收消息： {}",event);
        //后续的相关逻辑，比如写入数据库
    }
}
